﻿@{
    Layout = null;
}
<h2>添加角色</h2>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    @*<link href="//unpkg.com/layui@2.8.3/dist/css/layui.css" rel="stylesheet">*@
    <link href="~/Scripts/layui-v2.5.6/layui/css/layui.css" rel="stylesheet" />
</head>
<body>
    <!-- 给容器追加 class="layui-form-pane"，即可显示为方框风格 -->
    <form class="layui-form layui-form-pane" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">权限名称</label>
            <div class="layui-input-block">
                <input type="text" name="PermissionName" id="PermissionName" value="系统管理" autocomplete="off" placeholder="请输入" lay-verify="required" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" pane>
            <label class="layui-form-label">权限状态</label>
            <div class="layui-input-block">
                <input type="radio" name="state" id="state" value="可用" title="可用" checked>
                <input type="radio" name="state" id="state" value="不可用" title="不可用">
            </div>
        </div>
        <div class="layui-form-item">
            <button class="layui-btn" type="button" lay-submit lay-filter="btnAdd">确认</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </form>

    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="~/Scripts/layui-v2.5.6/layui/layui.js" asp-append-version="true"></script>
    <script>

        layui.use(['form', 'laydate'], function () {
            var form = layui.form
                , layer = layui.layer
            $ = layui.$;

            console.log(1111);

            // 提交事件
            form.on('submit(btnAdd)', function (data) {
                console.log(222222);
                data = data.field;
                data.state = data.state == "可用" ? true : false;
                $.post("/Permission/DoPermissionAdd", data,
                    res => {
                        console.log(res);
                        if (res) {
                            console.log(res);
                            layer.msg('添加权限成功', {
                                icon: 1,
                                time: 1000
                            }, function () {
                                window.location = '/Permission/Index';
                            });
                        }
                        else {
                            layer.msg('添加权限失败！', {
                                icon: 1,
                                time: 1000
                            });
                        }
                    }
                )
            });
        });
    </script>
</body>
</html>